package com.api.gbhg.zengping.dao;

import com.api.gbhg.zengping.common.CommonDao;
import weaver.conn.RecordSet;

import java.util.Map;

/**
 * @program: gbhg-oa
 * @description: 预算总额报表
 * @author: Mr.zeng
 * @create: 2021-03-03 11:34
 **/
public class TotalBudgetDao {


    /**
     *查询经费表  (预算总额报表)
     * @param map
     * @return
     */
    public static RecordSet selectByList(Map map){
        RecordSet rs=new RecordSet();
        String sql="select lcjlid,nd,sbdw,sum(ze)ze,sum(dj)dj,sum(syed)syed from uf_jingfei where 1=1";
        StringBuffer sb=new StringBuffer();
        sb.append(sql);
        if(null!=map.get("nd")){
            sb.append(" and nd="+map.get("nd"));
        }
        if(null!=map.get("dw")){
            sb.append(" and sbdw="+map.get("dw"));
        }
        sb.append("group by nd,sbdw,lcjlid ");
        int pageNum = (int)map.getOrDefault("pageNum", 0);
        int pageSize = (int)map.getOrDefault("pageSize", 10);
         sb.append(CommonDao.limitSql(pageNum!=0?(pageNum-1)*pageSize:0,pageSize,"lcjlid"));
        rs.executeQuery(sb.toString());
       return rs;
    }

    /**
     * 查询经费表条数  (预算总额报表)
     * @param map
     * @return
     */
    public static int selectByListCount(Map map){
        RecordSet rs=new RecordSet();
        String sql="select count(1) count from uf_jingfei where 1=1";
        StringBuffer sb=new StringBuffer();
        sb.append(sql);
        if(null!=map.get("nd")){
            sb.append(" and nd="+map.get("nd"));
        }
        if(null!=map.get("dw")){
            sb.append(" and sbdw="+map.get("dw"));
        }
        rs.executeQuery(sb.toString());
        rs.next();
        return rs.getInt("count");
    }

    public static int getSBKS(String lcjlid){
        RecordSet rs=new RecordSet();
        String sql="select sbks from uf_jingfei_version where lcjlsqjlid="+lcjlid;
        rs.executeQuery(sql);
        rs.next();
        return rs.getInt("sbks");
    }

    /**
     * 查询报销实际发生数
     * @param lcid
     * @return
     */
    public static  int selectReimbursementCount(String lcid){
        RecordSet rs=new RecordSet();
        String sql="select count(1)num from uf_jingfei_dt2 where xmlcid="+lcid;
        rs.executeQuery(sql);
        rs.next();
        return rs.getInt("num");
    }
}
